import * as constants  from './constants'
import {fromJS} from 'immutable'

const defaultState =  fromJS({
  focused: false,
  list: [],
  page: 1,
  totalPage: 1 ,
  mouseIn: false
});

// eslint-disable-next-line import/no-anonymous-default-export
export default (state = defaultState, action) => {
  // eslint-disable-next-line default-case
  switch(action.type) {
    case constants.SERACH_FOCUS : return state.set('focused',true)
    case constants.SERACH_BLUR :  return state.set('focused',false)
    case constants.CHANGR_LIST : 
      return state.merge({
        'list': action.data,
        'totalPage': action.totalPage
      })
    case constants.MOUSE_ENTER : return state.set('mouseIn',true)
    case constants.MOUSE_LEAVE : return state.set('mouseIn',false)
    case constants.CHANGE_PAGE : return state.set('page',action.page)
  }
  return state;
}
